/***********************************************************
 *
 * 说 明：用户信息查看、保存处理
 * 作 者：yangjianliang
 * 日 期：2007-11-1
 *
 **********************************************************/
package com.apexedu.identity.action;

import com.apexedu.framework.util.DBUtil;
import com.apexedu.identity.IdConstants;
import com.apexedu.identity.entity.TSysRole;
import com.apexedu.identity.entity.TSysUser;
import com.apexedu.identity.service.IdUserService;
import com.apexedu.portal.util.DBMUtil;
import com.apexedu.sys.action.AbstractBaseActionSupport;
import com.apexedu.sys.entity.ApplicationEnum;
import com.apexedu.util.StringUtil;
import org.apache.struts2.ServletActionContext;

import javax.persistence.Transient;
import javax.servlet.http.HttpSession;
import java.util.List;

public class IdUserAction extends AbstractBaseActionSupport {

    /**
     * 希望类的不同版本对序列化兼容，只要确保类的不同版本具有相同的serialVersionUID
     */
    private static final long serialVersionUID = 1L;

//	private static final Log LOG = LogFactory.getLog(IdUserAction.class);

    private TSysUser tsysUser;
    private List<TSysUser> tsysUsers;
    @Transient
    private IdUserService idUserService;

    /**
     * 用户修改密码
     *
     * @return Struts配置的转向标记（字符串）
     */
    public String modifyPassword() {

        HttpSession session = ServletActionContext.getRequest().getSession();
        TSysUser existMember = (TSysUser) session.getAttribute(IdConstants.SESSION_USER);

        String message = idUserService.modifyPassword(existMember, tsysUser);
        this.addActionMessage(message);

        return toView("repwd.jsp");
    }

    public TSysUser getTsysUser() {
        return tsysUser;
    }

    public void setTsysUser(TSysUser tsysUser) {
        this.tsysUser = tsysUser;
    }

    public IdUserService getIdUserService() {
        return idUserService;
    }

    public void setIdUserService(IdUserService idUserService) {
        this.idUserService = idUserService;
    }

    public List<TSysUser> getTsysUsers() {
        return tsysUsers;
    }

    public void setTsysUsers(List<TSysUser> tsysUsers) {
        this.tsysUsers = tsysUsers;
    }

    /**
     * 获取 所属部门的下拉框数据,返回拼装后的js数据
     */
    public void departsJS() {
        this.putResultStringToView(idUserService.departsJS());
    }

    /**
     * 用于页面上获取所有的角色名
     */
    public List<TSysRole> getAllRoles() {
        return idUserService.getAllRoles();
    }

    /**
     * 将门户TUser表中的数据，提交到t_sys_user表中。
     */
    public void extractUsers() {
        String msg = idUserService.exportUsers();
        if (StringUtil.isBlank(msg)) {
            msg = "同步失败！";
        }
        putResultStringToView(msg);
    }

    /**
     * 用户类型集合
     *
     * @return
     */
    public List<ApplicationEnum> getYhlxList() {
        return DBUtil.queryAllBeanList("select distinct yhlx as id,yhlxmc as caption from t_yhzd order by yhlx", ApplicationEnum.class);
    }
}
